package com.ydche.service.impl;

import com.cloopen.rest.sdk.CCPRestSmsSDK;
import com.ydche.idl_output.*;
import com.ydche.service.ISmsService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Set;


@Service
public class SmsServiceImpl implements ISmsService {
    private static Logger log = LogManager.getLogger(SmsServiceImpl.class);
    private static final String ACCOUNT_SID = "8aaf07085b8e61c6015b8f701b500116";
    private static final String AUTH_TOKEN = "d1a08f66cba1429c9c05ffcc060f051f";
    private static final String APP_ID = "8a216da85b8e6bb1015b8f736cf600c5";

    @Override
    public void sendLoginVerifyCode(String code, String mobile) throws RequestException{
        CCPRestSmsSDK restAPI = new CCPRestSmsSDK();
        restAPI.init("app.cloopen.com", "8883");
        restAPI.setAccount(ACCOUNT_SID, AUTH_TOKEN);
        restAPI.setAppId(APP_ID);

        HashMap<String, Object> result = restAPI.sendTemplateSMS(mobile, "178705",
                new String[]{code, "3"});
        if (!"000000".equals(result.get("statusCode"))) {
            //异常返回输出错误码和错误信息
            log.info("错误码=" + result.get("statusCode") + " 错误信息= " + result.get("statusMsg"));
        }
        return;
    }
}
